(function() {
	// 拷贝url
	function copyUrl() {
	    var input=document.getElementById("input-url");
	    var txt = input.select(); // 选择对象
	    document.execCommand("Copy","true", "true"); // 执行浏览器复制命令
	}
    
    // 获取站点信息
	(function() {
		var token = sessionStorage.getItem('token');
		var user_id = sessionStorage.getItem('user_id');
		var data = `user_id=${user_id}&token=${token}`;

		ajax({
		    type: 'POST',
		    url: 'public/api.web.php/web/mylist',
	        data: `user_id=${user_id}&token=${token}`,
	        onsuccess: function(res) {
	        	console.log(res);
	        	sessionStorage.setItem('web_data', JSON.stringify(res));
	        	webSelect(res);
	        	webInfo(res, 0);
	        },
	        onerror: function(res) {
	        	console.log(res);
	        }
		});
	}());

	// 生成站点选择列表
	function webSelect(res) {
		var text = '';
		for(var i in res.data) {
	        text += `<option value="${i}" data-id="${res.data[i].id}">${res.data[i].web_name}</option>`;
		}
		document.getElementById("sele").innerHTML += text;
	}

	// 站点信息生成
	function webInfo(res, id) {
		var infoUrl = "ftp://10.21.76.60/";
		var wid = id || 0;  //默认执行读取第一个站点的信息
		var pictureImgs = document.getElementsByClassName('picture-img');
		// for(var i = 0; i < pictureImgs.length; i++) {
		pictureImgs[0].setAttribute('src', 'images/' + res.data[wid].web_image);
		pictureImgs[1].setAttribute('src', 'images/' + res.data[wid].web_image1);
		pictureImgs[2].setAttribute('src', 'images/' + res.data[wid].web_image2);
		// }
		document.getElementById("name").innerText = res.data[wid].web_name;
		document.getElementsByClassName("team-content")[0].innerText = res.data[wid].web_info;
		document.getElementById("input-url").value = infoUrl + res.data[wid].web_name;
		switchoverUrl(res.data[wid].web_name);
	}

	// // 站点列表值发生改变更换不同的信息
	document.getElementById("sele").onchange = function () {
		var webId = this.value;
		var webData = JSON.parse(sessionStorage.getItem('web_data'));
		webInfo(webData, webId);
	};

	// 站点URL切换函数
	function switchoverUrl(webName) {
		var btn = document.getElementsByClassName("url-item");
		var inTxt = document.getElementById("input-url");
		btn[0].onclick = btn[1].onclick = function() {
			var a = this;
			var way = a.innerText;
			btn[0].className = "url-item";
			btn[1].className = "url-item";
			a.className = "url-item active";
			inTxt.value = way.toLowerCase() + "://10.21.76.60/" + webName;
		};
	}
}());